package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo6 {
	public static void main(String[] args) {
		try (Connection connection = DBUtil.getConnection();) {
			Statement statement = connection.createStatement();
			
			String sql = "select count(*) count,c.name " +
					"from student s "+
					"join class c on s.class_id=c.id " +
					"group by c.name ";
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()){
				int count = rs.getInt("count");
				String name = rs.getString("c.name");
				System.out.println(count + "," + name);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
